//
//  ExhibitionDetailViewController.m
//  homeland
//
//  Created by SunShine on 14-1-18.
//  Copyright (c) 2014年 xzysun. All rights reserved.
//

#import "ExhibitionDetailViewController.h"

@interface ExhibitionDetailViewController ()

@property (strong, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) NSArray *titleList;
@end

@implementation ExhibitionDetailViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"会展信息";
    self.titleList = @[@"展会名称", @"展览时间", @"承办单位", @"所属展馆"];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table Method
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 34.0;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, SCREEN_WIDTH-20, 24)];
    NSString *title = [self.titleList objectAtIndex:section];
    label.text = title;
    label.textAlignment = NSTextAlignmentLeft;
    label.textColor = [UIColor blueColor];
    label.backgroundColor = [UIColor clearColor];
    UIView *panel = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 34)];
    panel.backgroundColor = [UIColor clearColor];
    [panel addSubview:label];
    return panel;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        CGFloat height = [self caculateHeightWithoutPaddingForString:[self.infoItem objectForKey:@"title"] AndFontSize:17.0 AndWitdh:320.0];
        return MAX(44.0, height);
    }
    return 44.0;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"exhibitionDetailCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    if (indexPath.section == 0) {
        cell.textLabel.text = [self.infoItem objectForKey:@"title"];
        cell.textLabel.numberOfLines = 0;
    } else if (indexPath.section == 1) {
        cell.textLabel.text = [self.infoItem objectForKey:@"time"];
    } else if (indexPath.section == 2) {
        cell.textLabel.text = [self.infoItem objectForKey:@"cbdw"];
    } else if (indexPath.section == 3) {
        cell.textLabel.text = [self.infoItem objectForKey:@"sszg"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
@end
